package com.ysg.http.interceptor;

import android.util.Log;

import com.ysg.BuildConfig;
import com.ysg.utils.YAppUtil;
import com.ysg.utils.YChannelUtil;
import com.ysg.utils.YSPUtils;
import com.ysg.utils.YStringUtil;
import com.ysg.utils.constant.BaseConstants;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * token拦截器
 */
public class TokenInterceptor implements Interceptor {

    public TokenInterceptor() {
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        if (YStringUtil.isNotEmpty(YSPUtils.getInstance().getToken())){
            builder.addHeader("token", YSPUtils.getInstance().getToken()).build();
        }
        if (YStringUtil.isNotEmpty(YSPUtils.getInstance().getOAID())){
            builder.addHeader("oaid", YSPUtils.getInstance().getOAID()).build();
        }
        builder.addHeader("packageName", BaseConstants.PACKAGE_NAME).build();
        builder.addHeader("platform", YChannelUtil.getInstance().getPlatform()).build();
        builder.addHeader("version", ""+ YAppUtil.getVersionName()).build();
        return chain.proceed(builder.build());
    }
}